import { GetBlob } from 'services'
import { saveAs } from 'file-saver'
export const download = (url: string, params: any) => {
    return new Promise((resolve, reject) => {
        GetBlob(url, params).then((res: any) => {
            if (res.data && res.data.size === 0) {
                reject()
                return
            }
            const fileName = window.decodeURI(res.headers['content-disposition'].split('\'\'')[1])
            const blob: any = new Blob([res.data], { type: res.headers['content-type'] })
            saveAs(blob, fileName)
        }).catch((e) => {
            reject(e)
        })
    })
}